// function includeExJS(jsFilepath){
//     var exJS = document.createElement('script');
//     exJS.src = jsFilepath;
//     document.head.appendChild(exJS);
// }
// includeExJS("/base.js");

$(function () {

	//	ajax
	jQuery.axspost = function (path, linknum, isPOST, data, successfn, errorfn) {
		data = (data == null || data == "" || typeof (data) == "undefined") ? {} : data;
		$.ajax({
			type: isPOST,
			data: JSON.stringify(data),
			url: spliceUrl(path, linknum),
			dataType: "json",
			contentType: 'application/json',
			success: function (d) {
				if (d.success) {
					successfn(d.result);
				} else {
					errorfn(d.message);
				}

			},
			error: function (e) {
				errorfn(RESPONSE_ERROR_EMPTY);
			}
		});
	};

	jQuery.apost = function (url, data, successfn, errorfn) {
		jQuery.axspost(url, null, 'post', data, successfn, errorfn)
	}

	jQuery.aget = function (url, linknum, successfn, errorfn) {
		jQuery.axspost(url, linknum, 'get', {}, successfn, errorfn)
	}
	jQuery.aget1 = function (url, linknum, successfn, errorfn) {
		jQuery.axspost(url, linknum, 'get', successfn, errorfn)
	}

	//  本地储存数据
	jQuery.ownStore = {
		set: function (key, value) {
			if (value != null) {
				localStorage.setItem(key, JSON.stringify(value));
			}
		},
		get: function (key) {
			return JSON.parse(localStorage.getItem(key)) || "";
		},
		remove: function (key) {
			localStorage.removeItem(key);
		},
		clear: function () {
			localStorage.clear();
		},
		setPid: function (pid) {
			if (pid) {
				localStorage.setItem('pid', pid);
			}
		},
		getPid: function () {
			return localStorage.getItem('pid') || "";
		},
		removePid: function () {
			localStorage.removeItem('pid');
		},
		setStaffId: function (staffid) {
			if (staffid) {
				localStorage.setItem('staffid', staffid);
			}
		},
		getStaffId: function () {
			return localStorage.getItem('staffid') || "";
		},
		removeStaffId: function () {
			localStorage.removeItem('staffid');
		},
		setStaffName: function (staffname) {
			if (staffname) {
				localStorage.setItem('staffname', staffname);
			}
		},
		getStaffName: function () {
			return localStorage.getItem('staffname') || "";
		},
		removeStaffName: function () {
			localStorage.removeItem('staffname');
		},
	};



})

//调用
//$.axspost(getUrlHost()+"url",'post/get', data ,function(){alert("成功了");},function(){});
var RESPONSE_ERROR_EMPTY = '请求失败'

function getUrlHost() {
	return window.location.host.search('dps')!= -1 ? '/dps-jeecg-boot' : '/jeecg-boot'
	// return window.location.host.search('dps')!= -1 ? '/dps-jeecg-boot' : 'http://api.dtx-tech.com/jeecg-boot'
	// return URL_API;
}

/**
 * 拼接完整请求路径
 */
function spliceUrl(path, linknum) {
	if (linknum) {
		return getUrlHost() + path + linknum
	} else {
		return getUrlHost() + path
	}
}

function errorfn(e) {
	console.log('失败', e);
	syalert.syopen('alert3')
	$('.sy-content').text(e)
}



// 获取首页基础信息
var PATH_INDEXBASICINFO = '/108/01/1080104';
// 获取控制目标
var PATH_TARGET = '/achievement/weeksummary';
//查询血糖曲线
var PATH_SUGARLINE = '/101/01/1010101'
//血糖统计
var PATH_SUGARSTATISTICS = '/101/01/1010103?type=3&patientId='
//查询bmi曲线
var PATH_BMILINE = '/101/06/1010601'
//bmi统计
var PATH_BMISTATISTICS = '/101/06/1010603'
//查询腰围曲线
var PATH_WAISTLINE = '/101/09/1010901'
//腰围统计
var PATH_WAISTSTATISTICS = '/101/09/1010904'
//获取量表首页填写数据
var PATH_EVALUTIONCOUNT = '/evaluation/list'


